FROM repository.gridsum.com:8443/library/golang:1.16 as builder
# arg deployment token
ARG GIT_USERNAME
ARG GIT_TOKEN
ARG BRANCH=master
ARG VERSION=v0.0.0
ENV WORKSPACE=/data/workspace/tarzan

WORKDIR $WORKSPACE

COPY . /data/workspace/tarzan

ENV GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOPROXY=https://goproxy.cn,direct GOPRIVATE=gitlab.gridsum.com
ENV BUILD_PATH=cmd/

RUN  echo Commit: `git log --pretty='%s%b%B' -n 1`
RUN export GIT_COMMIT=`git rev-parse HEAD` && \
cd $WORKSPACE/$BUILD_PATH && go build -gcflags "all=-N -l" -ldflags "-X 'main.GitCommit=$GIT_COMMIT' -X 'main.Version=$VERSION'" -o /tmp/tarzan-installer .
FROM docker.gridsumdissector.com/library/centos:8
RUN yum install -y postgresql-server postgresql-contrib postgresql-devel postgresql postgresql-libs
RUN yum -y install mysql-server mysql mysql-devel
RUN mkdir -p /tarzan
WORKDIR /tarzan
COPY --from=builder /tmp/tarzan-installer /tarzan
COPY --from=builder /data/workspace/tarzan /tarzan
RUN chmod +x /tarzan/tarzan-installer
EXPOSE 8000

CMD ["/tarzan/tarzan-installer"]